package com.ruoyi.web.controller.test;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.ContractPayment;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.HolidayHomeStatistics;
import com.ruoyi.system.service.IHolidayHomeStatisticsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 节假日返乡统计Controller
 *
 * @author ruoyi
 * @date 2022-08-02
 */
@RestController
@RequestMapping("/system/statistics")
public class HolidayHomeStatisticsController extends BaseController
{
    @Autowired
    private IHolidayHomeStatisticsService holidayHomeStatisticsService;

    /**
     * 查询节假日返乡统计列表
     */
    @PreAuthorize("@ss.hasPermi('system:statistics:list')")
    @GetMapping("/list")
    public TableDataInfo list(HolidayHomeStatistics holidayHomeStatistics)
    {
        startPage();
        List<HolidayHomeStatistics> list = holidayHomeStatisticsService.selectHolidayHomeStatisticsList(holidayHomeStatistics);
        return getDataTable(list);
    }

    /**
     * 导出节假日返乡统计列表
     */
    @PreAuthorize("@ss.hasPermi('system:statistics:export')")
    @Log(title = "节假日返乡统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HolidayHomeStatistics holidayHomeStatistics)
    {
        List<HolidayHomeStatistics> list = holidayHomeStatisticsService.selectHolidayHomeStatisticsList(holidayHomeStatistics);
        ExcelUtil<HolidayHomeStatistics> util = new ExcelUtil<HolidayHomeStatistics>(HolidayHomeStatistics.class);
        util.exportExcel(response, list, "节假日返乡统计数据");
    }

    /**
     * 获取节假日返乡统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:statistics:query')")
    @GetMapping(value = "/{staId}")
    public AjaxResult getInfo(@PathVariable("staId") Long staId)
    {
        return AjaxResult.success(holidayHomeStatisticsService.selectHolidayHomeStatisticsByStaId(staId));
    }

    /**
     * 新增节假日返乡统计
     */
    @PreAuthorize("@ss.hasPermi('system:statistics:add')")
    @Log(title = "节假日返乡统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HolidayHomeStatistics holidayHomeStatistics)
    {
        holidayHomeStatistics.setUserId(getUserId());
        holidayHomeStatistics.setDeptId(getDeptId());
        return toAjax(holidayHomeStatisticsService.insertHolidayHomeStatistics(holidayHomeStatistics));
    }

    /**
     * 修改节假日返乡统计
     */
    @PreAuthorize("@ss.hasPermi('system:statistics:edit')")
    @Log(title = "节假日返乡统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HolidayHomeStatistics holidayHomeStatistics)
    {
        return toAjax(holidayHomeStatisticsService.updateHolidayHomeStatistics(holidayHomeStatistics));
    }

    /**
     * 删除节假日返乡统计
     */
    @PreAuthorize("@ss.hasPermi('system:statistics:remove')")
    @Log(title = "节假日返乡统计", businessType = BusinessType.DELETE)
    @DeleteMapping("/{staIds}")
    public AjaxResult remove(@PathVariable Long[] staIds)
    {
        return toAjax(holidayHomeStatisticsService.deleteHolidayHomeStatisticsByStaIds(staIds));
    }
    /**
     * 导入数据管理列表
     */
    @Log(title = "数据管理", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<HolidayHomeStatistics> util = new ExcelUtil<HolidayHomeStatistics>(HolidayHomeStatistics.class);
        List<HolidayHomeStatistics> contractPaymentList = util.importExcel(file.getInputStream());
       // List<HolidayHomeStatistics> contractPaymentList = util.importExcel(file.getInputStream());
//        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        String operName = getUsername();
        String message = holidayHomeStatisticsService.importPayment(contractPaymentList, updateSupport, operName);
        return AjaxResult.success(message);
    }
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<HolidayHomeStatistics> util = new ExcelUtil<HolidayHomeStatistics>(HolidayHomeStatistics.class);
        util.importTemplateExcel(response,"案卷数据");
    }
}
